package spring.demo.Validations;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

public class PersonValidator {

	public boolean supports(Class classObject) {
		return Person.class.equals(classObject);
	}

	public void validate(Object obj, Errors errors) {
		System.out.println("Inside validation");
		ValidationUtils.rejectIfEmpty(errors, "name", "nameEmpty");
		Person person = (Person) obj;
		if (person.getAge() < 0) {
			errors.rejectValue("age", "negativevalue");
		} else if (person.getAge() > 110) {
			errors.rejectValue("age", "too old");
		}
		System.out.println(errors);
	}

}
